Code
import numpy as np
import matplotlib.pyplot as plt
import statsmodels.api as sm
x = np.random.normal(50, 10, 100)
y = np.random.normal(2, 10, 100) + 2 * x + np.random.normal(0, 1, 100)
X = sm.add_constant(x)
lm = sm.OLS(y, X).fit()
y_hat = lm.predict()
plt.style.use('ggplot')
fig, ax = plt.subplots()
ax.scatter(y, x, color = "gray")
ax.plot(y_hat, x, color = "red")
plt.title('Regresión lineal')
plt.xlabel('X')
plt.ylabel('Y')
fig.show()